import axios from 'axios'

let api = {}
const path = 'http://localhost'
api.kugouSeach = function (keyword, callback) {
  axios.get('http://localhost:3000/kugou', { params: { musicName: keyword } }).then(res => {
    callback && callback(res)
  })
}

api.musicUrl = function (FileHash, AlbumID, callback) {
  axios.get('http://localhost:3000/getUrl', { params: { FileHash, AlbumID } }).then(res => {
    callback && callback(res)
  })
}

api.getTopList = function (callback) {
  let url = path + '/api/music/get?url=http://m.kugou.com/?json=true'
  axios.get(url).then(res => {
    callback && callback(res)
  })
}

api.ranking = function (callback) {
  let url = path + '/api/music/get?url=http://m.kugou.com/rank/list?json=true'
  axios.get(url).then(res => {
    callback && callback(res)
  })
}

api.rankInfo = function (rankid, page, callback) {
  let parms = encodeURIComponent(`http://m.kugou.com/rank/info/?rankid=${rankid}&page=${page}&json=true`)
  let url = path + `/api/music/get?url=${parms}`
  axios.get(url).then(res => {
    callback && callback(res)
  })
}

export default api
